package com.liang.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.util.ResourceUtils;

import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @ClassName SensitiveUtils.java
 * @createTime 2021年06月08日 21:43:00
 */
@Component
public class SensitiveUtils {
    private Logger logger = LoggerFactory.getLogger(SensitiveUtils.class);


    private static List<String> sensitiveList = new ArrayList<>();

    public void init() {
        try {
            StringBuffer sb = new StringBuffer();
            String readLine = null;
            InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(ResourceUtils.getFile("classpath:敏感词.txt")));
            BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
            while ((readLine = bufferedReader.readLine()) != null) {
                sb.append(readLine);
            }
            logger.info("readLine------------------" + sb.toString());
            sensitiveList = Arrays.asList(sb.toString().split("\\|"));
            logger.info("sensitiveList size------------------" + sensitiveList.size());

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public boolean isContain(String str) {
        boolean b = sensitiveList.contains(str);
        return b;
    }


}
